from flask import render_template, session, redirect, url_for

from . import main
# from .forms import NameForm
from .. import db
# from ..models import User,Role,Permission
from flask_login import login_required
from .forms import g_searchForm


# @main.before_app_first_request
# def initDB():
#     db.create_all()

@main.route('/')
def root():
    searchform = g_searchForm()
    return redirect(url_for('main.index'))

@main.route('/index')
def index():
    searchform = g_searchForm()
    return render_template('index.html', form=searchform)

@main.route('/course')
def main_course():
    searchform = g_searchForm()
    return render_template('allcourse.html', form=searchform)

@main.route('/path')
def main_path():
    searchform = g_searchForm()
    return render_template('path.html', form=searchform)

@main.route('/match')
def main_match():
    searchform = g_searchForm()
    return render_template('Match.html', form=searchform)

@main.route('/cloudear')
def main_cloudear():
    searchform = g_searchForm()
    return render_template('cloudeardic.html', form=searchform)

@main.route('/college')
def main_college():
    searchform = g_searchForm()
    return render_template('college.html',form=searchform)

@main.route('/notice')
def main_notice():
    searchform = g_searchForm()
    return render_template('notice.html',  form=searchform)


@main.route('/jupyterview')
def main_jupyterview():
    searchform = g_searchForm()
    return render_template('jupyterview.html', form=searchform)


@main.route('/createdir/<dirname>')
def main_createdir(dirname):
    from ..commAPI import hostObj
    hostObj.mkdir(dirname)
    return redirect(url_for('main.main_jupyterview'))
